#include "edfparser.h"
#include <algorithm>
#include <map>
#include <iostream>
#include <iterator>


#include <biosignal.h>

/*

 void display_double(double val) {
 std::cout << val << " | ";
 }

 */

using namespace std;
using namespace std::tr1;



void display_data(const biosignal::SignalDataContent& sd) {
//		cout << " data : " << sd->signal_info().lock()->label() << "  : " ;
	//for_each(sd.begin(), sd.end(), PrintCaller<FrameIterationTest>(this) );
	biosignal::DataIterator it;
	cout << "--------------- inicio senial  -----------" << endl;
	for(it = sd->begin(); it!= sd->end(); ++it) {
		cout << *it << " | " ;
	}
	cout << "----------------fin senial -----------" << endl;
}



void display(const shared_ptr<biosignal::DataFrame>& df)
{
	cout << " time : " << df->time() << " signals : "
			<< df->signal_data().size() << endl;
	biosignal::DataFrame::const_iterator it;
	for(it = df->begin(); it!=df->end(); ++it ) {
		display_data(*it);

	}
}



/*
void display(EDFDataRecord::DataRecord_const_ptr sdr)
{
	const EDFDataRecord* dr = sdr.get();

	EDFDataRecord::s_data::const_iterator it;
	EDFDataRecord::s_data vdouble = dr->data()[0];
	std::cout << "display data_record : " << dr->data_record_id() << " [ "
			<< vdouble.size() << " ]  -  ";

	for_each(vdouble.begin(), vdouble.end(), display_double);
	std::cout << std::endl;

}
*/
using namespace biosignal::edf;

class EDFLoadTest
{
public:
	void loadEDF()
	{
		const char* file_name = "test_generator.edf";
		//       qDebug("loading edf file : %s" , file_name );

		const EDFModel* edf_model = EDFParser::parse(file_name);
		std::cout << "   ================= signal data =============="
				<< std::endl;

		std::ostream_iterator<double> ost_it(std::cout, " - ");
		//edf_model->show_signal_data( ost_it );


		iterate(edf_model);

		//edf_model->data.begin();
		std::cout << std::endl
				<< "!!!================= signal data ==============!!!"
				<< std::endl;
		edf_model->show_header_info(std::cout);

		delete edf_model;
	}

	void iterate(const EDFModel* edf_model, int n = 4)
	{
		biosignal::SignalSlice slice = edf_model->signal();
		biosignal::DataFrameIterator it = slice.begin();
		for (int i = 0; i < n; i++)
		{
			display(*it);
			it++;
		}

	}

};

int main(int argc, const char* argv[])
{
	EDFLoadTest test;
	test.loadEDF();

}

